//package com.example.pets.model.datasource.DataSourceImpl;
//
//
//import androidx.lifecycle.LiveData;
//import androidx.lifecycle.MutableLiveData;
//
//import com.example.pets.model.datasource.ClueDataSource;
//import com.example.pets.model.entities.Clue;
//import com.google.firebase.firestore.CollectionReference;
//import com.google.firebase.firestore.FirebaseFirestore;
//import com.google.firebase.firestore.QueryDocumentSnapshot;
//import com.google.firebase.firestore.DocumentReference;
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class ClueDataSourceImpl implements ClueDataSource {
//
//    private final CollectionReference clueCollection;
//
//    public ClueDataSourceImpl() {
//        FirebaseFirestore db = FirebaseFirestore.getInstance();
//        clueCollection = db.collection("clues");
//    }
//
//    @Override
//    public LiveData<Clue> getClueById(String clid) {
//        MutableLiveData<Clue> clueLiveData = new MutableLiveData<>();
//        clueCollection.document(clid)
//                .addSnapshotListener((snapshot, error) -> {
//                    if (error != null || snapshot == null || !snapshot.exists()) {
//                        clueLiveData.setValue(null);
//                        return;
//                    }
//                    Clue clue = snapshot.toObject(Clue.class);
//                    clueLiveData.setValue(clue);
//                });
//        return clueLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> addClue(Clue clue) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        clueCollection.add(clue)
//                .addOnSuccessListener(docRef -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> updateClue(String clid, Clue clue) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        clueCollection.document(clid)
//                .set(clue)
//                .addOnSuccessListener(aVoid -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<Boolean> deleteClue(String clid) {
//        MutableLiveData<Boolean> resultLiveData = new MutableLiveData<>();
//        clueCollection.document(clid)
//                .delete()
//                .addOnSuccessListener(aVoid -> resultLiveData.setValue(true))
//                .addOnFailureListener(e -> resultLiveData.setValue(false));
//        return resultLiveData;
//    }
//
//    @Override
//    public LiveData<List<Clue>> getCluesByLost(DocumentReference lostRef) {
//        MutableLiveData<List<Clue>> listLiveData = new MutableLiveData<>();
//        clueCollection.whereEqualTo("lost", lostRef)
//                .addSnapshotListener((querySnapshot, error) -> {
//                    if (error != null || querySnapshot == null) {
//                        listLiveData.setValue(null);
//                        return;
//                    }
//                    List<Clue> clueList = new ArrayList<>();
//                    for (QueryDocumentSnapshot doc : querySnapshot) {
//                        Clue clue = doc.toObject(Clue.class);
//                        clueList.add(clue);
//                    }
//                    listLiveData.setValue(clueList);
//                });
//        return listLiveData;
//    }
//
//    @Override
//    public LiveData<List<Clue>> getCluesByProvider(DocumentReference providerRef) {
//        MutableLiveData<List<Clue>> listLiveData = new MutableLiveData<>();
//        clueCollection.whereEqualTo("provider", providerRef)
//                .addSnapshotListener((querySnapshot, error) -> {
//                    if (error != null || querySnapshot == null) {
//                        listLiveData.setValue(null);
//                        return;
//                    }
//                    List<Clue> clueList = new ArrayList<>();
//                    for (QueryDocumentSnapshot doc : querySnapshot) {
//                        Clue clue = doc.toObject(Clue.class);
//                        clueList.add(clue);
//                    }
//                    listLiveData.setValue(clueList);
//                });
//        return listLiveData;
//    }
//
//    @Override
//    public LiveData<List<Clue>> getAllClues() {
//        MutableLiveData<List<Clue>> listLiveData = new MutableLiveData<>();
//        clueCollection.addSnapshotListener((querySnapshot, error) -> {
//            if (error != null || querySnapshot == null) {
//                listLiveData.setValue(null);
//                return;
//            }
//            List<Clue> clueList = new ArrayList<>();
//            for (QueryDocumentSnapshot doc : querySnapshot) {
//                Clue clue = doc.toObject(Clue.class);
//                clueList.add(clue);
//            }
//            listLiveData.setValue(clueList);
//        });
//        return listLiveData;
//    }
//}
